﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TMIS.BLL
{
    public class Login
    {
        private TMIS.DAL.Student sdal = new DAL.Student();
        private TMIS.DAL.Teacher tdal = new DAL.Teacher();
        /// <summary>
        /// 根据用户姓名级用户密码判断用户是否存在
        /// </summary>
        /// <param name="name">用户姓名</param>
        /// <param name="password">用户密码</param>
        /// <returns>存在返回true，不存在返回false</returns>
        public bool Check(string name, string password,string identity)
        {
            if (identity == "学生")
            {
                if (sdal.Check(name, password) != Guid.Empty)
                    return true;
                else
                    return false;
            }
            else
            {
                if (tdal.Search(name, password) != 0)
                    return true;
                else
                    return false;   
            }
        }

        /// <summary>
        /// 根据用户姓名、用户密码、用户身份获取该用户对应的ID
        /// </summary>
        /// <param name="name">用户姓名</param>
        /// <param name="password">用户密码</param>
        /// <param name="identity">用户身份</param>
        /// <returns></returns>
        public Guid Get(string name, string password, string identity)
        {
            if (identity == "学生")
            {
                return sdal.Get(name, password);
            }
            else
            {
                return tdal.Get(name, password);
            }
        }

        /// <summary>
        ///将学生基本信息添加进入到数据库中
        /// </summary>
        /// <param name="name">学生姓名</param>
        /// <param name="password">学生密码</param>
        public void Add(string name, string password)
        {
            Model.Student student=new Model.Student ()
            {
                ID=Guid.NewGuid(),
                sName=name,
                sPassword=password
            };
            sdal.Add(student);
        }
    }
}
